<?php
	class ArcControl extends CommonControl{

		function index(){
			$db = k("arc");
			$total = $db->count();
			$page = new page($total);
			$row = $db->where('hs=0')->order('aid desc')->findAll($page->limit());
			$this->assign('row',$row);
			$this->display();
			echo $page->show();//显示分页页码
		}

		function send (){	
			$db=M('category');
			$result=$db->all();
			$this->assign('result',$result);
			$this->display();
		}

		function runsend(){			
			$data=$_POST;
			$data['addtime']=time();
			$data['thumbimg']=$_POST['thumbimg']['1']['path'];
			$db=M('arc');
			if($db->add($data)){
				$this->success('发布成功','index');
			}else{
				$this->error('发布失败，请重试');
			}
		}

		function editshow(){
			$aid=$_GET['aid'];
			$sql="select * from ".C('DB_PREFIX')."arc where aid=".$aid;
			$result=M()->query($sql);
			$thumbimg=array(
				array(
					'alt'=>'',
					'path'=>$result[0]['thumbimg'],
					"thumb" => array($result[0]['thumbimg'])
				)				
			);
						
			$this->assign('thumbimg',$thumbimg);
			$this->assign('result',$result);
			$this->display();		
		}

		function runedit(){
			$thumb=isset($_POST['thumbimg'][1]['path']) ? $_POST['thumbimg'][1]['path'] : '';
			$sql="update ".C('DB_PREFIX')."arc set 
					title = '$_POST[title]', 
					keywords='$_POST[keywords]', 
					content='$_POST[content]' , 
					description='$_POST[description]',
					thumbimg='$thumb' where aid=$_POST[aid]";
			if(M()->exe($sql) >= 0){
				$this->success('修改成功');
			}else{
				$this->error('修改失败，请重试');
			}
		}

		function arcdel(){
			$aid=$_POST['aid'];
			$db=M('arc');
			$sql = "update ".C('DB_PREFIX')."arc set hs=1 where aid='$_POST[aid]'";
			if(M()->exe($sql)>=0){
				echo json_encode(array('status'=>1,'msg'=>'删除成功'));
			}else{
				echo json_encode(array('status'=>0,'msg'=>'删除失败'));
			}
		}

		function delall(){
			$arr=$_POST['arr'];
			$num=array();
			$db=M('arc'); 
			foreach ($arr as $v) {
				if ($db->del($v['aid'])>0) {
					$num['i']=1;
				}
			}
			echo json_encode($num);
		}

		function huishou(){
			$db=M('arc');
			$result = $db->where('hs = 1')->all();
			$this->assign('result',$result);
			$this->display();
		}

		function huanyuan(){
			$sql="update ".C('DB_PREFIX')."arc set hs=0 where aid='$_GET[aid]'";
			if (M()->exe($sql)>=0) {
				$this->success('还原成功');
			}
		}

		function arcdie(){
			$aid=$_GET['aid'];
			$db=M('arc');
			if($db->del($aid)){
				$this->success('删除成功');
			}else{
				$this->error('删除失败，请重试');
			}
		}

		function yulan(){
			$aid=$_GET['aid'];
			
		}
	}
?>